<template>
  <div class="mcontaner">
  <el-row :gutter="20">
    <el-col :span="16" :offset="4"></el-col>
  
  </el-row>
    <el-row :gutter="20">
  <el-col :span="4">
  <navMenu></navMenu>
  </el-col>
  <el-col :span="16">
  
  <Header></Header>
    <search class="search"  @changeval='handleval' :blogsHotWrods="blogs"></search>
    <div class="block">
      <el-timeline>

        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
                {{blog.title}}
              </router-link>
            </h4>
            <p>{{blog.description}}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>

      <el-pagination class="mpage"
                     background
                     layout="prev, pager, next"
                     :current-page="currentPage"
                     :page-size="pageSize"
                     :total="total"
                     @current-change=page>
      </el-pagination>

    </div>
    </el-col>
  <el-col :span="4">
  
  <calendar></calendar>
    
  </el-col>
</el-row>


  </div>
</template>

<script>
  import Header from "../components/Header";
  import search from "./search";
  import calendar from "./calendar";
  import navMenu from "./nav";

  export default {
    name: "Blogs.vue",
    components: {Header,search,calendar,navMenu},
    data() {
      return {
        blogs: [],
        currentPage: 1,
        total: 0,
        pageSize: 5,
        input: '',
        value: new Date()
      }
    },
    methods: {
      page(currentPage) {
        const _this = this
         
        _this.$axios.get("/blogs?currentPage=" + currentPage).then(res => {


          // console.log(res)
          _this.blogs = res.data.data.records
          
		      // console.log("_this.blogs")
		      // console.log(_this.blogs)

          _this.currentPage = res.data.data.current
          _this.total = res.data.data.total
          _this.pageSize = res.data.data.size

        })
        
      },
      handleval (e) {
        const _this = this
        this.$axios.get("/blog/search/wd="+e).then(res => {
           _this.blogs={}            //清空才能刷新         
          _this.blogs[0] = res.data.data
	        _this.$router.push("/blogs").catch(err => err)
        })
      }
    },
    created() {
      this.page(1)
    }
  }
</script>

<style scoped>

  .mpage {
    margin: 0 auto;
    text-align: center;
  }
  .btn {
    width:50px;
    height:20px;
  }
  >>> .el-calendar {
    height:200px;
  }
  .calendar {
    height:20px;
  }
  .search {
    /* margin: 0 auto;*/
  }
</style>